/*
 * @Author: your name
 * @Date: 2021-01-25 20:26:42
 * @LastEditTime: 2021-01-25 23:42:30
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \ad-api\service\contentService.js
 */
const { addContentDao ,getContentDao  ,delContentDao} = require('../dao')
const path = require('path')
const fs = require('fs')
module.exports = {
   // 获取页面列表
  getContentService: async (page_id)=>{
    return await getContentDao(page_id)
  }, 
  //添加页面图片
  addContentService: async (param)=>{
    return await addContentDao(param)
  },
  //删除图片
  delContentService: async (content_id, img_name) => {
   const { status } = await delContentDao(content_id)
   if (status) {
       const imgUrl = path.resolve(__dirname, `../public/img/${img_name}`)
       const delResult = await new Promise((resolve, reject) => {
           fs.unlink(imgUrl, (error) => {
               if (error) {
                   console.log('删除本地文件失败', error);
                   return resolve(false)
               }
               console.log('删除文件成功');
               return resolve(true)
           })
       })
       return delResult
       // return true
   }
},
}
